﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ReadSolutionContents
{
    class SolutionReader
    {
        public string[] GetFilesForProject(string solution)
        {
            List<string> filelist = new List<string>();
            SolutionFile slnfile = new SolutionFile(solution);
            slnfile.Load();

            foreach (var project in slnfile.CSharpProjectFiles)
            {
                project.Load();
                project.SourceFiles.ToList().ForEach(e => filelist.Add(e.FilePath));
            }

            return filelist.ToArray();
        }

        public string[] GetEachSolution(string directoryPath)
        {
            if (Directory.Exists(directoryPath))
            {
                string[] files = Directory.GetFiles(directoryPath, "*.sln", SearchOption.AllDirectories);
                return files;
            }
            else
            {
                throw new DirectoryNotFoundException();
            }
        }

        public string[] GetAllCSharpFiles(string directorypath)
        {
            if (Directory.Exists(directorypath))
            {
                string[] files = Directory.GetFiles(directorypath, "*.cs", SearchOption.AllDirectories);
                return files;
            }
            else
            {
                throw new DirectoryNotFoundException();
            }
        }
    }
}
